package com.example.kinytx.apr5;

/**
 * Created by Administrator on 2015-3-11.
 */
public class CallsignAPRSCalculate {
    private static final long BASE_HASH = 0x73E2;

    public static String calculate (String cs)
    {
        long hash = BASE_HASH;
        char[] chars = cs.toUpperCase().toCharArray();
        for (int j = 0; j < chars.length; j += 2)
        {
            hash ^=  (int)chars[j]  << 8;
            if(chars.length > j + 1)
                hash ^=  (int)chars[j+1];
        }
        return chars.length > 0 ? Long.toString(hash & 0x7fff) : "";
    }
}
